//
//  TPViewController.m
//  Pods
//
//  Created by caixun on 15/11/6.
//
//

#import "TPViewController.h"


#pragma mark - iOS版本判断
#define IsIOS8Lower ([[[UIDevice currentDevice] systemVersion] floatValue]<8.0) // iOS8以下
#define IsIOS7Lower ([[[UIDevice currentDevice] systemVersion] floatValue]<7.0) // iOS7以下

#define TP_TPVC_Color_BG        [UIColor whiteColor]    /// 背景色


@interface TPViewController ()


@end


@implementation TPViewController


#pragma mark - *********************************** View Lifecycle **********************************

- (id)init
{
    self = [super init];
    if (self)
    {
        [self foreverFullScreenFit]; /// 统一坐标
        
        self.isSupportShouShiBack = YES;
    }
    
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    /// 设置通用背景色
    self.view.backgroundColor = TP_TPVC_Color_BG;
    
    NSLog(@"\n((((((%@ viewDidLoad))))))\n", NSStringFromClass([self class]));
}

- (void)dealloc
{
    NSLog(@"\n((((((%@ dealloc))))))\n", NSStringFromClass([self class]));
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self stateBarIsShow:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self stateBarIsShow:NO];
    
    [super viewWillDisappear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - *********************************** Init All Views **********************************


#pragma mark - ************************************* Functions *************************************

#pragma mark - 判断当前VC是否第一优先级

- (BOOL)isFirstResponderController
{
    NSArray *array = self.navigationController.viewControllers;
    
    if (array.count > 0 && [[array lastObject] isEqual:self])
    {
        return YES;
    }
    
    return NO;
}

#pragma mark - 适配iOS6，7坐标点统一为屏幕(0,0)点

- (void)foreverFullScreenFit
{
    if (IsIOS7Lower)
    {
        self.wantsFullScreenLayout = YES;
    }
    else
    {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

#pragma mark - 设置是否显示状态栏，需要isFullScreenFat来判断
/*!
 *  @brief  设置是否显示状态栏，需要isFullScreenFat来判断
 *  该方法应用在最国美这样的全屏显示页面,无导航栏，需要将isFullScreenFat属性设置为YES，才会生效
 *
 *  @param isShow 显示不显示工具栏
 *
 *  @since 9.303
 */
- (void)stateBarIsShow:(BOOL)isShow
{
    if (self.isFullScreenFat)
    {
        [[UIApplication sharedApplication] setStatusBarHidden:isShow
                                                withAnimation:UIStatusBarAnimationNone];
    }
    else
    {
        /// 如果VC中没有声明self.isFullScreenFat，则默认self.isFullScreenFat=NO，显示状态栏
        [[UIApplication sharedApplication] setStatusBarHidden:NO
                                                withAnimation:UIStatusBarAnimationNone];
    }
}


@end
